package cn.wd.service.impl;

import cn.wd.domain.Book;
import cn.wd.mapper.BookMapper;
import cn.wd.qo.QueryObject;
import cn.wd.service.IBookService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements IBookService {

    private final BookMapper bookMapper;

    public BookServiceImpl(BookMapper bookMapper) {
        this.bookMapper = bookMapper;
    }

    @Override
    public void insert(Book book) {
        bookMapper.insert(book);
    }

    @Override
    public void delete(Long id) {
        bookMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Book book) {
        bookMapper.updateByPrimaryKey(book);
    }

    @Override
    public Book selectById(Long id) {
        return bookMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Book> selectAll() {
        return bookMapper.selectAll();
    }

    @Override
    public PageInfo<Book> selectForList(QueryObject qo) {
        PageHelper.startPage(qo.getCurrent(), qo.getPageSize());
        List<Book> bookList = bookMapper.selectForList(qo);
        return new PageInfo<>(bookList);
    }
}
